package com.fenghuo.utils;

import android.content.Context;
import android.location.LocationManager;
import android.util.DisplayMetrics;
import android.view.WindowManager;

public class Utils {
	
	
	public static int getScreenWidth(Context context){
		WindowManager manager=(WindowManager) context.getSystemService(Context.WINDOW_SERVICE);
		return manager.getDefaultDisplay().getWidth();
	}
	
	public static int getScreenHeight(Context context){
		WindowManager manager=(WindowManager) context.getSystemService(Context.WINDOW_SERVICE);
		DisplayMetrics metrics=new DisplayMetrics();
		manager.getDefaultDisplay().getMetrics(metrics);
		return metrics.heightPixels;
	}
	
	public static int getpx(Context context,float dip){
		float density = context.getResources().getDisplayMetrics().density;
		return (int)(dip*density+0.5f);
	}
	
	public static int getdip(Context context,int px){
		float density=context.getResources().getDisplayMetrics().density;
		return (int)(px/density+0.5f); 
	}

	public static  boolean getGpsavalible(Context context){
		LocationManager manager=(LocationManager) context.getSystemService(Context.LOCATION_SERVICE);
		if(manager.isProviderEnabled(LocationManager.GPS_PROVIDER)){
			return true;
		}else{
//			Toast.makeText(this, "请开启GPS！", Toast.LENGTH_SHORT).show();
//		    Intent intent = new Intent(Settings.ACTION_SECURITY_SETTINGS);
//		    startActivityForResult(intent,0); //此为设置完成后返回到获取界面
			return false;
		}
	}
}
